class Solution{
public:
  vector<vector<int>> threeSum(vector<int> &nums){
    //a+b+c = 0 --> a+b = -c
    std::sort(nums.begin(), nums.end());
    vector<vector<int>> v2;
    for(int c = nums.size() - 1; c >= 2;){
      for(int a = 0, b = c - 1; a < b;){
        int tmp_sum = nums[a] + nums[b];
        if(tmp_sum < -nums[c]){
          ++a;
        }else if(tmp_sum > -nums[c]){
          --b;
        }else{
          vector<int> v = {nums[a], nums[b], nums[c]};
          v2.push_back(v);
          do{//去重复 a b
            ++a;
          }while(a < b && nums[a - 1] == nums[a]);
          do{
            --b;
          }while(a < b && nums[b + 1] == nums[b]);
        }
      }
      do{//去重复 c
        --c;
      }while(c >= 2 && nums[c + 1] == nums[c]);
    }
    return v2;

  }
};